/*
	created time:2018/4/8
	author:Chason
	describe:开始游戏背景
*/
class GameBackground extends egret.DisplayObjectContainer{
	public constructor() {
		super();
		this.init();
		//监听添加到显示列表
		this.addEventListener(egret.Event.ADDED_TO_STAGE,()=>{
           this.start();
        }, this);		
	}

	private  stageWidth=egret.MainContext.instance.stage.stageWidth;
	private  stageHeight=egret.MainContext.instance.stage.stageHeight;

	public start(){
		//游戏背景音乐
		let musicArr:Array<string>=['gameing1_mp3','gameing2_mp3','exciting_mp3'];
		//随机音乐
		let musicIndex=Math.floor(Math.random()*(3));
		Music.musicPlay(musicArr[musicIndex]);
	}

    //初始化	
	public init():void{
		//游戏背景
		let bg:egret.Bitmap=new egret.Bitmap();
        //随机获取背景
		let bgNum=parseInt((Math.random()*9+1).toString());
		bg.texture=RES.getRes(`screenGameBg_json.gamebg${bgNum}`);
		bg.width=this.stageWidth;
		bg.height=this.stageHeight;
		this.addChild(bg);
	}
}